/*
 *    Copyright (c) 2018-2025, nart All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: nart
 */
package com.nai365.nart.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nai365.nart.product.entity.Brand;
import com.nai365.nart.product.entity.CategoryBrandRelation;
import com.nai365.nart.product.mapper.CategoryBrandRelationMapper;
import com.nai365.nart.product.service.BrandService;
import com.nai365.nart.product.service.CategoryBrandRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 品牌分类关联
 *
 * @author baogs
 * @date 2022-07-01 11:05:46
 */
@Service
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationMapper, CategoryBrandRelation> implements CategoryBrandRelationService {

	@Autowired
	private CategoryBrandRelationMapper relationDao;
	@Autowired
	private BrandService brandService;
	@Override
	public List<Brand> getBrandsByCatId(Long catId) {

		List<CategoryBrandRelation> catelogId = relationDao.selectList(new QueryWrapper<CategoryBrandRelation>().eq("catelog_id", catId));

		List<Brand> collect = catelogId.stream().map(item -> {
			Long brandId = item.getBrandId();
			//查询品牌的详情
			Brand byId = brandService.getById(brandId);
			return byId;
		}).collect(Collectors.toList());

		return collect;
	}
}
